package com.ljye.jg.ljye.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ljye.jg.ljye.R;
import com.ljye.jg.ljye.activity.Activity_Circle_Management;
import com.ljye.jg.ljye.activity.Activity_Course_Management;
import com.ljye.jg.ljye.activity.Activity_Personal_Data;
import com.ljye.jg.ljye.activity.Activity_Qualification_Certification;
import com.ljye.jg.ljye.activity.Activity_Teacher_Home;
import com.ljye.jg.ljye.activity.Activity_Visit_Today;
import com.ljye.jg.ljye.activity.Actvivty_School_Begins;
import com.timqi.sectorprogressview.ColorfulRingProgressView;
import com.youth.banner.Banner;


/**
 * Created by Administrator on 2016/9/29.
 */
public class Fragment_home extends Fragment {

    public static Banner banner;//轮播
    String[] images = new String[]{
            "http://img.zcool.cn/community/0166c756e1427432f875520f7cc838.jpg",
            "http://img.zcool.cn/community/018fdb56e1428632f875520f7b67cb.jpg",
            "http://img.zcool.cn/community/01c8dc56e1428e6ac72531cbaa5f2c.jpg",
            "http://img.zcool.cn/community/01fda356640b706ac725b2c8b99b08.jpg",
            "http://img.zcool.cn/community/01fd2756e142716ac72531cbf8bbbf.jpg",};
    Integer[] imageer = {R.drawable.banner_1, R.drawable.banner_2, R.drawable.banner_3};
    private View view;
    private TextView progresstext1;//进度条1文字
    private ColorfulRingProgressView crpv1;//进度条1
    private TextView progresstext2;//进度条2文字
    private ColorfulRingProgressView progress2;//进度条2
    private TextView progresstext3;//进度条3文字
    private ColorfulRingProgressView progress3;//进度条3
    private LinearLayout schoolBegins;//我要开课
    private LinearLayout courseManagement;//课程管理
    private LinearLayout circleManagement;//圈子管理
    private LinearLayout personalData;//个人资料
    private LinearLayout today;//今日访问
    private LinearLayout certification;//资历认证
    private LinearLayout home;//我的主页


    private Intent intent;
    public View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.school_begins://我要开课
                    intent = new Intent(getActivity(), Actvivty_School_Begins.class);
                    startActivity(intent);
                    break;
                case R.id.course_management://课程管理
                    intent = new Intent(getActivity(), Activity_Course_Management.class);
                    startActivity(intent);
                    break;
                case R.id.circle_management://圈子管理
                    intent = new Intent(getActivity(), Activity_Circle_Management.class);
                    startActivity(intent);
                    break;
                case R.id.personal_data://个人资料
                    intent = new Intent(getActivity(), Activity_Personal_Data.class);
                    startActivity(intent);
                    break;
                case R.id.today://今日访问
                    intent = new Intent(getActivity(), Activity_Visit_Today.class);
                    startActivity(intent);
                    break;
                case R.id.certification://资历认证
                    intent = new Intent(getActivity(), Activity_Qualification_Certification.class);
                    startActivity(intent);
                    break;
                case R.id.home://我的主页
                    intent = new Intent(getActivity(), Activity_Teacher_Home.class);
                    startActivity(intent);
                    break;

                default:
                    break;
            }
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_home, null);

            //初始化控件
            initview();
            initAutoBanner();//初始化轮播图
            initprogress(70, 60, 100);//初始化进度条
            //我要开课点击监听
            schoolBegins.setOnClickListener(listener);
            courseManagement.setOnClickListener(listener);
            circleManagement.setOnClickListener(listener);
            personalData.setOnClickListener(listener);
            today.setOnClickListener(listener);
            certification.setOnClickListener(listener);
            home.setOnClickListener(listener);

        }

        return view;
    }

    private void initview() {
        banner = (Banner) view.findViewById(R.id.banner);
        crpv1 = (ColorfulRingProgressView) view.findViewById(R.id.sector_progress1);
        schoolBegins = (LinearLayout) view.findViewById(R.id.school_begins);
        progresstext1 = (TextView) view.findViewById(R.id.progress1);
        progresstext2 = (TextView) view.findViewById(R.id.progresstext2);
        progress2 = (ColorfulRingProgressView) view.findViewById(R.id.progress2);
        progresstext3 = (TextView) view.findViewById(R.id.progresstext3);
        progress3 = (ColorfulRingProgressView) view.findViewById(R.id.progress3);
        personalData = (LinearLayout) view.findViewById(R.id.personal_data);
        courseManagement = (LinearLayout) view.findViewById(R.id.course_management);
        circleManagement = (LinearLayout) view.findViewById(R.id.circle_management);
        today = (LinearLayout) view.findViewById(R.id.today);
        home = (LinearLayout) view.findViewById(R.id.home);
        certification = (LinearLayout) view.findViewById(R.id.certification);
    }

    //进度条
    private void initprogress(int number1, int number2, int number3) {
        crpv1.setPercent(number1);
        progress2.setPercent(number2);
        progress3.setPercent(number3);
        progresstext1.setText(number1 + "%");
        progresstext2.setText(number2 + "%");
        progresstext3.setText(number3 + "%");
    }

    //轮播图
    private void initAutoBanner() {
        //设置样式,默认为:Banner.NOT_INDICATOR(不显示指示器和标题)
        //可选样式如下:
        //1. Banner.CIRCLE_INDICATOR    显示圆形指示器
        //2. Banner.NUM_INDICATOR   显示数字指示器
        //3. Banner.NUM_INDICATOR_TITLE 显示数字指示器和标题
        //4. Banner.CIRCLE_INDICATOR_TITLE  显示圆形指示器和标题
        banner.setBannerStyle(Banner.CIRCLE_INDICATOR);
        //设置轮播样式（没有标题默认为右边,有标题时默认左边）
        //可选样式:
        //Banner.LEFT   指示器居左
        //Banner.CENTER 指示器居中
        //Banner.RIGHT  指示器居右
        banner.setIndicatorGravity(Banner.CENTER);
        banner.isAutoPlay(true);//设置是否自动轮播（不设置则默认自动）
        banner.setDelayTime(2000);//设置轮播图片间隔时间（不设置默认为2000）
        banner.setImages(imageer);
        //自定义图片加载框架
//        banner.setImages(images, new Banner.OnLoadImageListener() {
//            @Override
//            public void OnLoadImage(ImageView view, Object url) {
//
//                for (int i = 0; i < images.length; i++) {
//                    Picasso.with(getActivity()).load(images[i]).into(view);
//                }
//            }
//        });
        //设置点击事件，下标是从1开始
        banner.setOnBannerClickListener(new Banner.OnBannerClickListener() {//设置点击事件
            @Override
            public void OnBannerClick(View view, int position) {
                Toast.makeText(getActivity(), "你点击了：" + position, Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        banner.isAutoPlay(true);
        Log.i("Fragment", "出现");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i("Fragment", "消失111");
        banner.isAutoPlay(false);
    }
}